package com.eorchis.module.trainingquestionnaire.ui.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.eorchis.core.page.commond.JSONObject;
import com.eorchis.core.service.IBaseService;
import com.eorchis.core.springext.mvc.SessionConstant;
import com.eorchis.core.ui.commond.ResultState;
import com.eorchis.core.ui.controller.AbstractBaseController;
import com.eorchis.module.classcourse.querybean.ClassCourseQueryBean;
import com.eorchis.module.classcourse.service.IClassCourseService;
import com.eorchis.module.classcourse.ui.commond.ClassCourseQueryCommond;
import com.eorchis.module.loginauthentication.domain.LoginAuthenticationBean;
import com.eorchis.module.loginauthentication.service.ILoginAuthenticationService;
import com.eorchis.module.trainingclass.domain.BaseUserBean;
import com.eorchis.module.trainingclass.domain.TrainingClass;
import com.eorchis.module.trainingclass.querybean.TrainingClassQueryBean;
import com.eorchis.module.trainingclass.service.ITrainingClassService;
import com.eorchis.module.trainingclass.ui.commond.TrainingClassQueryCommond;
import com.eorchis.module.trainingclass.ui.commond.TrainingClassValidCommond;
import com.eorchis.module.trainingquestionnaire.domain.ExportClassQuestionnaireSheet;
import com.eorchis.module.trainingquestionnaire.domain.ExportQuestionnaireBean;
import com.eorchis.module.trainingquestionnaire.domain.MCQStatisticsBean;
import com.eorchis.module.trainingquestionnaire.domain.QuestionnaireEntity;
import com.eorchis.module.trainingquestionnaire.domain.QuestionnaireQueryBean;
import com.eorchis.module.trainingquestionnaire.domain.ScoreStatisticsBean;
import com.eorchis.module.trainingquestionnaire.domain.userquestionnairebean.EssayQuestionInfo;
import com.eorchis.module.trainingquestionnaire.domain.userquestionnairebean.ItemOption;
import com.eorchis.module.trainingquestionnaire.domain.userquestionnairebean.PaperInfo;
import com.eorchis.module.trainingquestionnaire.domain.userquestionnairebean.SelectProblemInfo;
import com.eorchis.module.trainingquestionnaire.domain.userquestionnairebean.StudentInfo;
import com.eorchis.module.trainingquestionnaire.domain.userquestionnairebean.StudentPageInfo;
import com.eorchis.module.trainingquestionnaire.service.IQuestionnaireService;
import com.eorchis.module.trainingquestionnaire.service.IUserAnswerLinkService;
import com.eorchis.module.trainingquestionnaire.ui.commond.QuestionnaireQueryCommond;
import com.eorchis.module.trainingquestionnaire.ui.commond.QuestionnaireValidCommond;
import com.eorchis.module.trainingquestionnaire.ui.commond.UserAnswerLinkQueryCommond;
import com.eorchis.module.user.domain.User;
import com.eorchis.utils.BeanUtils;
import com.eorchis.utils.DateUtil;
import com.eorchis.utils.excelutil.export.bo.Sheet;
import com.eorchis.utils.utils.PropertyUtil;

/**
 * Title: UserQuestionnaireController<br>
 * Description: 前台页面问卷管理控制器<br>
 * Company: GoldGov<br>
 * Copyright @ 2012 GoldGov .All rights reserved.<br>
 * 
 * @author Administrator
 * @createDate 2014-08-27
 * @version $Revision$
 */
@Controller("userQuestionnaireController")
@RequestMapping(value = UserQuestionnaireController.MODULE_PATH)
public class UserQuestionnaireController extends AbstractBaseController<QuestionnaireValidCommond, QuestionnaireQueryCommond> {
	// 模块页面根路径
	public static final String MODULE_PATH = "/module/userquestionnaire";
	// 调查问卷接口
	@Autowired
	@Qualifier("main.java.com.eorchis.module.trainingquestionnaire.service.impl.QuestionnaireServiceImpl")
	private IQuestionnaireService questionnaireService;
	// 班级课程维护接口
	@Autowired
	@Qualifier("com.eorchis.module.classcourse.service.impl.ClassCourseServiceImpl")
	private IClassCourseService classCourseService;
		
	// 用户答卷关联信息接口
	@Autowired
	@Qualifier("com.eorchis.module.trainingquestionnaire.service.impl.UserAnswerLinkServiceImpl")
	private IUserAnswerLinkService userAnswerLinkService;
	
	// 实验室资源接口
	@Resource(name = "com.eorchis.module.loginauthentication.service.impl.LoginAuthenticationServiceImpl")
	private ILoginAuthenticationService loginAuthenticationService;
	
	// 培训班信息接口
	@Autowired
	@Qualifier("com.eorchis.module.trainingclass.service.impl.TrainingClassServiceImpl")
	private ITrainingClassService trainingClassService; // 培训班信息接口

	public IBaseService getService() {
		return questionnaireService;
	}

	public String getModulePath() {
		return MODULE_PATH;
	}

	public String getPageBasePath() {
		return "/portal/project/classquestionnaire";
	}

	/**
	 * 打开调查问卷之前的检查
	 * @param queryCommond
	 * @param request
	 * @param resultState
	 * @return
	 * @throws Exception
	 * @author HuangTF
	 * @date 2014-09-09
	 */
	@RequestMapping(value = "preOpenQuestionnairePaper")
	public void preOpenQuestionnairePaper(@ModelAttribute("resultList") QuestionnaireQueryCommond queryCommond,@ModelAttribute("List")QuestionnaireQueryCommond q,HttpServletRequest request, HttpServletResponse response,ResultState resultState) throws Exception {
		resultState.setState(ResultState.RESULT_STATE_FAIL);// 默认失败
		String mess="";	
		User user = (User) request.getSession().getAttribute(SessionConstant.USER_INFO);
		if(!PropertyUtil.objectNotEmpty(user)){
			System.out.println("用户信息失效!");
			request.getRequestDispatcher("/module/userquestionnaire/userLogin.do").forward(request,response);
			return;
		}
		try{
			mess = this.checkUserQuestionnaireInfo(queryCommond, request);	
		}catch(Exception e){
			e.printStackTrace();
			System.out.println("用户信息失效!");
			request.setAttribute("searchClassId", queryCommond.getSearchClassId());
			request.getRequestDispatcher(this.getPageBasePath()+"/questionnaire.jsp").forward(request,response);
			return;
//			return "redirect:/module/userquestionnaire/userLogin.do?method=scan&searchClassId="+queryCommond.getSearchClassId();
		}
		resultState.setMessage(mess);
		if (mess.equals("success")) {
			System.out.println("十1");
//			resultState.setState(ResultState.RESULT_STATE_SUCCESS);
//			return "forward:/portal/project/classquestionnaire/questionnaire.jsp";
			request.setAttribute("searchQuestionnaireId", queryCommond.getSearchQuestionnaireId());
			request.setAttribute("searchClassId", queryCommond.getSearchClassId());
			request.setAttribute("token", this.token.saveToken(request));
			request.getRequestDispatcher(this.getPageBasePath()+"/questionnaire.jsp").forward(request,response);
//			response.sendRedirect("/pxfiles/portal/project/classquestionnaire/questionnaire.jsp");
			return;
		} 
//		else {
//			String userId = ((User) request.getSession().getAttribute(SessionConstant.USER_INFO)).getUserID();
//			queryCommond.setSearchUserId(userId);
//			System.out.println("十2");
//			
//			String re = queryUserQuestionnaireList(queryCommond,q,new QuestionnaireValidCommond(), request,response, resultState);
//			System.out.println("十一");
//			return ;
//		}
		
		 /*return
		 "redirect:/module/userquestionnaire/queryUserQuestionnaireList.do?searchClassId="
		 +queryCommond.getSearchClassId()+"&searchUserId="+queryCommond.
		 getSearchUserId()+"&searchMsg="+queryCommond.get;*/
		 
	}

	/**
	 * 检查用户问卷信息
	 * 
	 * @param queryCommond
	 * @param request
	 * @return
	 * @throws Exception
	 * @author HuangTF
	 * @date 2014-09-11
	 */
	private String checkUserQuestionnaireInfo(QuestionnaireQueryCommond queryCommond, HttpServletRequest request) throws Exception {
		if (!PropertyUtil.objectNotEmpty(queryCommond.getSearchQuestionnaireId()))
			return "调查问卷ID为空！";
		QuestionnaireValidCommond commond = questionnaireService.find(queryCommond.getSearchQuestionnaireId());
		// 判断问卷是否已经作废
		if (commond.getActiveState().intValue() == QuestionnaireQueryCommond.IS_CANCEL.intValue())
			return "该问卷已撤销！";
		// 判断问卷是否已经发布
		if (commond.getPublishState().intValue() == QuestionnaireEntity.IS_PUBLISH_N.intValue())
			return "该问卷已撤销！";
		// 判断是否在答卷时间内
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		QuestionnaireValidCommond validcommond = new QuestionnaireValidCommond();
		validcommond.setClassId(queryCommond.getSearchClassId());
		QuestionnaireQueryBean questionnaireQueryBean = questionnaireService.assessTime(validcommond);
		Date start = DateUtil.changeDate0H0m0s0ms(new Date());
		Date end = DateUtil.changeDate23H59m59s999ms(new Date());
		if(PropertyUtil.objectNotEmpty(questionnaireQueryBean)){
			if (PropertyUtil.objectNotEmpty(questionnaireQueryBean.getAssessStartDay())) {
				if (simpleDateFormat.parse(questionnaireQueryBean.getAssessStartDay()).after(end))
					return "该问卷未开始！";
			}
			if (PropertyUtil.objectNotEmpty(questionnaireQueryBean.getAssessEndDay())) {
				if (simpleDateFormat.parse(questionnaireQueryBean.getAssessEndDay()).before(start))
					return "该问卷已经结束！";
			}
		}else{
			QuestionnaireValidCommond qv=questionnaireService.findCourseInfo(validcommond);
			if(simpleDateFormat.parse(qv.getAssessCourseStartDay()).after(end)){
				return "该问卷未开始！";
			}
			if(simpleDateFormat.parse(qv.getAssessCourseEndDay()).before(start)){
				return "该问卷已经结束！";
			}
			
		}
//		User user = (User) request.getSession().getAttribute(SessionConstant.USER_INFO);
		/*
		 * //判断当前用户是否在问卷调查范围内 List<String>
		 * userIdList=questionnaireService.querySurveyObjectNum(queryCommond);
		 * if(!userIdList.contains(user.getUserID())) return "您不在该问卷调查范围内";
		 */
		// 判断用户是否已经参加调查问卷
		queryCommond.setSearchUserId(queryCommond.getSearchUserId());
		if (questionnaireService.isJoinQuestionnaire(queryCommond))
			return "check";
		return "success";
	}

	/**
	 * 打开调查问卷
	 * 
	 * @param queryCommond
	 * @param request
	 * @return
	 * @throws Exception
	 * @author HuangTF
	 * @date 2014-09-09
	 */
	@RequestMapping(value = "openQuestionnairePaper")
	public @ResponseBody
	JSONObject openQuestionnairePaper(QuestionnaireValidCommond commond, HttpServletRequest request) throws Exception {
		JSONObject result = this.openPaper(commond, request);
		return result;
	}

	/**
	 * 打开调查问卷逻辑
	 * 
	 * @param commond
	 * @param request
	 * @return
	 * @throws Exception
	 * @author HuangTF
	 * @date 2014-09-09
	 */
	private JSONObject openPaper(QuestionnaireValidCommond commond, HttpServletRequest request) throws Exception {
		JSONObject result = new JSONObject();
		if (PropertyUtil.objectNotEmpty(commond.getEntityID())) {
			// 当前登陆用户
			User user = (User) request.getSession().getAttribute(SessionConstant.USER_INFO);
			StudentInfo studentInfo = new StudentInfo();
			studentInfo.setUserId(user.getUserId());
			studentInfo.setUserName(user.getUserName());
			// 构建调查问卷
			PaperInfo pageInfo = questionnaireService.createQuestionnaireInfo(commond);
			// 获取答案信息，如果存在用户提交的信息获取该信息，否则获取暂存的答卷信息
			UserAnswerLinkQueryCommond queryCommond = new UserAnswerLinkQueryCommond();
			queryCommond.setSearchQuestionnaireId(commond.getQuestionnaireId());
			queryCommond.setSearchUserId(user.getUserId());
			queryCommond.setSearchClassId(commond.getClassId());
			Map<String, List<String>> questionAnswerMap = new LinkedHashMap<String, List<String>>();
			QuestionnaireQueryCommond questionnaireQueryCommond = new QuestionnaireQueryCommond();
			questionnaireQueryCommond.setSearchQuestionnaireId(commond.getQuestionnaireId());
			questionnaireQueryCommond.setSearchUserId(user.getUserId());
			questionnaireQueryCommond.setSearchClassId(commond.getClassId());
			if (questionnaireService.isJoinQuestionnaire(questionnaireQueryCommond)) {
				questionAnswerMap = userAnswerLinkService.queryUserAnswer(queryCommond);
			}
			// else
			// {
			// questionAnswerMap=userAnswerLinkService.queryUserAnswerLinkTemp(queryCommond);
			// }
			// 匹配试题和答案
			pageInfo = this.updateQuestionnaireAnswerInfo(pageInfo, questionAnswerMap);

			pageInfo.setSelectProblemInfoGroup(questionnaireService.problemSets(pageInfo.getSelectProblemInfo()));
			// 查询班级信息
			TrainingClassValidCommond co = trainingClassService.find(commond.getClassId());
			StudentPageInfo studentPageInfo = new StudentPageInfo();
			studentPageInfo.setPageInfo(pageInfo);
			studentPageInfo.setStudentInfo(studentInfo);
			studentPageInfo.setToken(token.saveToken(request));
			if(!PropertyUtil.objectNotEmpty(co)){
				//查询课程信息
				QuestionnaireValidCommond qv=questionnaireService.findCourseInfo(commond);
				commond.setClassName(qv.getCourseName());
				commond.setBeginDateStr(qv.getAssessCourseStartDay());
				commond.setEndDateStr(qv.getAssessCourseEndDay());
				commond.setSpeaker(qv.getSpeaker());
				commond.setMinistrieName(qv.getSpeaker());
				commond.setSpeakWay(qv.getSpeakWay());
				commond.setFlag(2);
				commond.setQuestionnaireMethod(PropertyUtil.objectNotEmpty(qv.getQuestionnaireMethod())?qv.getQuestionnaireMethod():TrainingClass.QUESTIONNAIRE_METHOD_TYPE_S);
			}else{
				// 存放班级信息
				commond.setClassName(co.getClassName());// 班级名称
//				commond.setMinistrieName(co.getMinistrieName());// 承办部委
				commond.setSponsorName(co.getTrainingClass().getSponsorName());// 主办单位
				commond.setBeginDateStr(new SimpleDateFormat("yyyy-MM-dd").format(co.getBeginDate()));// 开班时间
				commond.setEndDateStr(new SimpleDateFormat("yyyy-MM-dd").format(co.getEndDate()));// 结班时间
				commond.setFlag(1);
				commond.setQuestionnaireMethod(PropertyUtil.objectNotEmpty(co.getTrainingClass().getQuestionnaireMethod())?co.getTrainingClass().getQuestionnaireMethod():TrainingClass.QUESTIONNAIRE_METHOD_TYPE_S);
			}
			commond.setStudentPageInfo(studentPageInfo);
			result.setData(commond);
			result.setSuccess(true);
		} else {
			result.setMsg("调查问卷ID为空！");
			result.setSuccess(false);
		}
		return result;
	}

	private PaperInfo updateQuestionnaireAnswerInfo(PaperInfo pageInfo, Map<String, List<String>> questionAnswerMap) throws Exception {
		List<SelectProblemInfo> selectProblemInfo = pageInfo.getSelectProblemInfo();
		for (SelectProblemInfo bean : selectProblemInfo) {
			if (questionAnswerMap.containsKey(bean.getItemId())) {
				List<String> answer = questionAnswerMap.get(bean.getItemId());
				for (ItemOption io : bean.getItemOption()) {
					if (answer.contains(io.getOptionNum())) {
						io.setIsSelect(true);
					}
				}
			}
		}
		List<SelectProblemInfo> multipleSelectProblemInfo = pageInfo.getMultipleSelectProblemInfo();
		for (SelectProblemInfo bean : multipleSelectProblemInfo) {
			if (questionAnswerMap.containsKey(bean.getItemId())) {
				List<String> answer = questionAnswerMap.get(bean.getItemId());
				for (ItemOption io : bean.getItemOption()) {
					for (String s : answer) {
						if (s.startsWith(io.getOptionNum())) {
							if (new Integer(1).equals(io.getObjectiveTopic())) {
								if (s.length() > 1) {
									io.setOptionAnswer(s.substring(1, s.length()));
								}
							}
							io.setIsSelect(true);
						}
					}
				}
			}
		}
		List<EssayQuestionInfo> essayQuestionInfo = pageInfo.getEssayQuestionInfo();
		for (EssayQuestionInfo bean : essayQuestionInfo) {
			if (questionAnswerMap.containsKey(bean.getQuestionId())) {
				if (PropertyUtil.objectNotEmpty(questionAnswerMap.get(bean.getQuestionId())) && questionAnswerMap.get(bean.getQuestionId()).size() > 0) {
					bean.setQuestionAnswer(questionAnswerMap.get(bean.getQuestionId()).get(0));
				}
			} else {
				bean.setQuestionAnswer("");
			}
		}
		return pageInfo;
	}

	/**
	 * 用户查看答卷信息之前的检查
	 * 
	 * @param queryCommond
	 * @param request
	 * @param resultState
	 * @return
	 * @throws Exception
	 * @author HuangTF
	 * @date 2014-11-17
	 */
	@RequestMapping(value = "checkUserQuestionnaireInfo")
	public void checkUserQuestionnaireInfo(QuestionnaireQueryCommond queryCommond, HttpServletRequest request,HttpServletResponse response, ResultState resultState) throws Exception {
		// resultState.setState(ResultState.RESULT_STATE_FAIL);//默认失败
		// String mess="";
		// QuestionnaireValidCommond
		// commond=questionnaireService.find(queryCommond.getSearchQuestionnaireId());
		// if(!PropertyUtil.objectNotEmpty(commond))
		// {
		// mess="该问卷已撤销！";
		// resultState.setMessage(mess);
		// return "forward:" + this.getPageBasePath() + "/list.jsp";
		// }
		// //判断是否在答卷时间内
		// Date start=DateUtil.changeDate0H0m0s0ms(new Date());
		// if(commond.getEndDate().before(start))
		// {
		// mess="该问卷已经结束！";
		// resultState.setMessage(mess);
		// return "forward:" + this.getPageBasePath() + "/list.jsp";
		// }

		resultState.setState(ResultState.RESULT_STATE_SUCCESS);
//		return "forward:" + this.getPageBasePath() + "/questionnaireAndAnswer.jsp";

		request.setAttribute("searchClassId", queryCommond.getSearchClassId());
		request.setAttribute("searchQuestionnaireId", queryCommond.getSearchQuestionnaireId());
		request.getRequestDispatcher(this.getPageBasePath()+"/questionnaireAndAnswer.jsp").forward(request,response);
		return ;
	}

	/**
	 * 用户查看答卷信息
	 * 
	 * @param commond
	 * @param request
	 * @param resultState
	 * @return
	 * @throws Exception
	 * @author HuangTF
	 * @date 2014-11-15
	 */
	@RequestMapping(value = "queryUserQuestionnaireInfo")
	public @ResponseBody
	JSONObject queryUserQuestionnaireInfo(QuestionnaireValidCommond commond, HttpServletRequest request, ResultState resultState) throws Exception {
		JSONObject result = this.openPaper(commond, request);
		return result;
	}

	/**
	 * @判断人员是否存在
	 * @Name: userLogin
	 * @Description: @param queryCommond
	 * @Description: @param request
	 * @Description: @param response
	 * @Description: @param resultState
	 * @Description: @return
	 * @Description: @throws Exception
	 * @Author: RongSL
	 * @Version: V1.00
	 * @Create Date: 2016-2-14上午10:03:57
	 * @Parameters: LoginAuthenticationController
	 * @Return: String
	 */
	@RequestMapping("/userLogin")
	public void userLogin(@ModelAttribute("resultList") QuestionnaireQueryCommond queryCommond,@ModelAttribute("List")QuestionnaireQueryCommond q,QuestionnaireValidCommond commond, HttpServletRequest request,HttpServletResponse response,
			@ModelAttribute("resultState") ResultState resultState) throws Exception {

		//当班级编号不为空时，始终查询班级编号
		queryCommond.setSearchClassId(questionnaireService.findClassId(queryCommond));
		//删除错误信息
		request.removeAttribute("error");
		// 跳转到列表
		String forwardPath = this.getPageBasePath()+"/login.jsp?method=scan&searchClassId="+queryCommond.getSearchClassId();
		//默认失败
		resultState.setState(ResultState.RESULT_STATE_SUCCESS);
		User user =(User) request.getSession().getAttribute(SessionConstant.USER_INFO);
		if(PropertyUtil.objectNotEmpty(user)&&"null".equals(queryCommond.getSearchUserLoginId())){
			queryCommond.setSearchUserLoginId(user.getLoginID());
		}else{
			user=new User();
		}
		if(PropertyUtil.objectNotEmpty(queryCommond.getSearchClassId())){
			request.setAttribute("searchClassId", queryCommond.getSearchClassId());
			int i=loginAuthenticationService.isAssessmentMode(queryCommond);
			//如果是匿名评估则跳过登录
			if(i!=0){
				String sessionId=request.getSession().getId();
				user.setUserId(sessionId);
				user.setLoginID(sessionId);
				user.setUserName("学员");
				request.getSession().setAttribute(SessionConstant.USER_INFO, user);
				String result= this.queryUserQuestionnaireList(queryCommond, q, commond, request, response,resultState);
				request.setAttribute("searchUserLoginId", user.getLoginID());
				request.setAttribute("searchQuestionnaireId", queryCommond.getSearchQuestionnaireId());
				request.setAttribute("resultList", queryCommond.getResultList());
				request.setAttribute("List", q.getResultList());
				if(result.equals("one")){		//单个已考
					request.getRequestDispatcher(this.getPageBasePath()+"/questionnaireAndAnswer.jsp").forward(request,response);
				}else if(result.equals("two")){		//单个未考（问卷打开）
					request.getRequestDispatcher(this.getPageBasePath()+"/questionnaire.jsp").forward(request,response);
				}else if(result.equals("three")){		//单个未考（列表打开）
					request.getRequestDispatcher(this.getPageBasePath()+"/list.jsp").forward(request,response);
				}else if(result.equals("error")){		//回话过期
					request.getRequestDispatcher(this.getPageBasePath()+"/questionnaire.jsp").forward(request,response);
				}else if(result.equals("four")){		//多个问卷
					request.getRequestDispatcher(this.getPageBasePath()+"/list.jsp").forward(request,response);
				}else{
					request.getRequestDispatcher(this.getPageBasePath()+"/list.jsp").forward(request,response);
					return ;
				}
			}else{
				LoginAuthenticationBean loginAuthentication = null;
				// 判断是否为登录页面
				if (PropertyUtil.objectNotEmpty(queryCommond.getSearchUserLoginId())) {
					// 是判断这个人是否存在
					loginAuthentication = loginAuthenticationService.userLogin(queryCommond);
					if (PropertyUtil.objectNotEmpty(loginAuthentication)) {
						queryCommond.setSearchUserId(loginAuthentication.getUserId());
						if (loginAuthenticationService.isThisClassUser(queryCommond)) {
							user.setUserId(loginAuthentication.getUserId());
							user.setUserName(loginAuthentication.getUserNmae());
							user.setLoginID(queryCommond.getSearchUserLoginId());
							request.getSession().setAttribute(SessionConstant.USER_INFO, user);
							resultState.setState(ResultState.RESULT_STATE_SUCCESS);
							String result= this.queryUserQuestionnaireList(queryCommond, q, commond, request, response,resultState);
							request.setAttribute("searchUserLoginId", user.getLoginID());
							request.setAttribute("searchQuestionnaireId", queryCommond.getSearchQuestionnaireId());
							request.setAttribute("resultList", queryCommond.getResultList());
							request.setAttribute("List", q.getResultList());
							if(result.equals("one")){		//单个已考
								request.getRequestDispatcher(this.getPageBasePath()+"/questionnaireAndAnswer.jsp").forward(request,response);
							}else if(result.equals("two")){		//单个未考（问卷打开）
								request.getRequestDispatcher(this.getPageBasePath()+"/questionnaire.jsp").forward(request,response);
							}else if(result.equals("three")){		//单个未考（列表打开）
								request.getRequestDispatcher(this.getPageBasePath()+"/list.jsp").forward(request,response);
							}else if(result.equals("error")){		//回话过期
								request.getRequestDispatcher(this.getPageBasePath()+"/questionnaire.jsp").forward(request,response);
							}else if(result.equals("four")){		//多个问卷
								request.getRequestDispatcher(this.getPageBasePath()+"/list.jsp").forward(request,response);
							}else{
								request.setAttribute("error", "程序异常，请重新扫码");
								request.getRequestDispatcher(forwardPath).forward(request,response);
								return ;
							}
						} else {
							resultState.setState(ResultState.RESULT_STATE_FAIL);
							request.setAttribute("error", "用户非本班学员，请检查后重新输入");
							request.getRequestDispatcher(forwardPath).forward(request,response);
							return ;
						}
					} else {
						// 跳转到login
						resultState.setState(ResultState.RESULT_STATE_FAIL);
						request.setAttribute("error", "用户不存在，请检查后重新输入");
						request.getRequestDispatcher(forwardPath).forward(request,response);
						return ;
					}
				}else{
					request.getRequestDispatcher(forwardPath).forward(request,response);
					return ;
				}
			}
		}else{
			request.getRequestDispatcher(forwardPath).forward(request,response);
			return ;
		}
	}
	
	/**
	 * 用户查看答卷信息
	 * 
	 * @param commond
	 * @param request
	 * @param resultState
	 * @throws Exception
	 * @author RongSL
	 * @date 2014-11-15
	 */
	@RequestMapping(value = "/JumpHome")
		public void JumpHome(@ModelAttribute("resultList") QuestionnaireQueryCommond queryCommond,@ModelAttribute("List")QuestionnaireQueryCommond q,QuestionnaireValidCommond commond, HttpServletRequest request,HttpServletResponse response,
				ResultState resultState) throws Exception {
	}
	
	/**
	 * 用户查看答卷信息
	 * 
	 * @param commond
	 * @param request
	 * @param resultState
	 * @throws Exception
	 * @author GUOLEI
	 * @date 2014-11-15
	 */
	@RequestMapping(value = "/queryUserQuestionnaireList")
	public String queryUserQuestionnaireList(@ModelAttribute("resultList") QuestionnaireQueryCommond queryCommond,@ModelAttribute("List")QuestionnaireQueryCommond q,QuestionnaireValidCommond commond, HttpServletRequest request,HttpServletResponse response,
			ResultState resultState) throws Exception {

		String result = "";
		Date start = DateUtil.changeDate0H0m0s0ms(new Date());
		Date end = DateUtil.changeDate23H59m59s999ms(new Date());

		User user = (User) request.getSession().getAttribute(SessionConstant.USER_INFO);
		queryCommond.setSearchUserId(user.getUserId());
		queryCommond.setSearchClassId(questionnaireService.findClassId(queryCommond));
		List<QuestionnaireQueryBean> questionnaireQueryList = questionnaireService.queryUserQuestionnaireList(queryCommond);
		TrainingClassQueryCommond com=new TrainingClassQueryCommond();
		com.setSearchClassId(queryCommond.getSearchClassId());
		TrainingClassQueryBean tc=trainingClassService.findThematicClassList(com).get(0);
		for(QuestionnaireQueryBean list:questionnaireQueryList){
			list.setQuestionnaireName(tc.getClassName());
			list.setSponsorName(tc.getSponsorName());
			if(new SimpleDateFormat("yyyy-MM-dd").parse(tc.getAssessStartTimeStr()).after(end)){
				list.setAssessmentState(1);//未开始
			}else if(new SimpleDateFormat("yyyy-MM-dd").parse(tc.getAssessEndTimeStr()).before(start)){
				list.setAssessmentState(4);//已过期
			}else{
				list.setAssessmentState(2);//正在评估
			}
			if(list.getTestCondition()==2){
				list.setAssessmentState(3);//已评估
			}
		}
		
		queryCommond.setResultList(questionnaireQueryList);
		
		List<QuestionnaireQueryBean> qList=new ArrayList<QuestionnaireQueryBean>();
		ClassCourseQueryCommond  qCommond=new ClassCourseQueryCommond();
		qCommond.setExistQuestionnaire("yes");
		qCommond.setSearchClassId(queryCommond.getSearchClassId());
		qCommond.setUserId(queryCommond.getSearchUserId());
		List<ClassCourseQueryBean> list=classCourseService.findAssessCourseList(qCommond);
		QuestionnaireQueryCommond qu = null;
		for(ClassCourseQueryBean ccqb:list){
			qu=new QuestionnaireQueryCommond();
			qu.setSearchUserId(queryCommond.getSearchUserId());
			qu.setSearchClassId(ccqb.getClassCourseId());
			List<QuestionnaireQueryBean> qq=questionnaireService.queryUserQuestionnaireList(qu);
			for(QuestionnaireQueryBean bean:qq){
				bean.setQuestionnaireName(ccqb.getQuestionnaireName());
				bean.setCourseName(ccqb.getCourseName());
				bean.setCourseId(ccqb.getClassCourseId());
				bean.setSpeaker(ccqb.getSpeaker());
				if(new SimpleDateFormat("yyyy-MM-dd").parse(ccqb.getAssessCourseStartDateStr()).after(end)){
					bean.setAssessmentState(1);//未开始
				}else if(new SimpleDateFormat("yyyy-MM-dd").parse(ccqb.getAssessCourseEndDateStr()).before(start)){
					bean.setAssessmentState(4);//已过期
				}else{
					bean.setAssessmentState(2);//正在评估
				}
				BigInteger bi;
				if(ccqb.getCourseAnswerState()==1){
					bean.setAssessmentState(3);//已评估
					bi=new BigInteger("2");
					bean.setTestCondition(bi);
				}else{
					bi=new BigInteger("1");
					bean.setTestCondition(bi);
				}
			}
			qList.addAll(qq);
		}
		if(PropertyUtil.objectNotEmpty(qList)){
			qu.setResultList(qList);
			BeanUtils.copyProperties(qu, q);
		}
		
		if (PropertyUtil.objectNotEmpty(questionnaireQueryList) && questionnaireQueryList.size() == 1&&!PropertyUtil.objectNotEmpty(q.getResultList())) {
			queryCommond.setSearchQuestionnaireId(questionnaireQueryList.get(0).getQuestionnaireId());
			commond.setQuestionnaireId(questionnaireQueryList.get(0).getQuestionnaireId());
			commond.setClassId(queryCommond.getSearchClassId());
			if (PropertyUtil.objectNotEmpty(questionnaireQueryList.get(0).getTestCondition()) && questionnaireQueryList.get(0).getTestCondition() == 2) {
				return "one";
			} else {
				// 未考过
				try{
					result = this.checkUserQuestionnaireInfo(queryCommond, request);
				}catch(Exception e){
					System.out.println("用户信息失效!");
					return "error";
				}
				if (result.endsWith("success")) {
					System.out.println("九1");
					return "two";
				} else {
					System.out.println("九2");
					return "three";
				}
			}
		}else{
			return "four";
		}
	}

	/**
	 * 原始汇总导出&学员评估详情导出
	 * @param commond
	 * @param request
	 * @return
	 * @throws Exception
	 * @author RongSl
	 * @date 2016-02-24
	 */
	@RequestMapping("/exportPaper")
	public void exportPaper(@ModelAttribute("resultList") QuestionnaireValidCommond commond, HttpServletRequest request, HttpServletResponse response,
			@ModelAttribute("resultState") ResultState resultState) throws Exception {
		resultState.setState(ResultState.RESULT_STATE_FAIL);// 默认失败
		List<Sheet> sheetList = new ArrayList<Sheet>();
		List<BaseUserBean> userList = null;
		TrainingClassQueryCommond TCCommond = new TrainingClassQueryCommond();
		if (PropertyUtil.objectNotEmpty(commond.getClassId()) && PropertyUtil.objectNotEmpty(commond.getEntityID())) {
			TCCommond.setSearchClassId(commond.getClassId());
			TCCommond.setSearchQuestionnaireId(commond.getQuestionnaireId());
			TCCommond.setAnswerUserStatus(1);
			TCCommond.setPage(-1);
			userList = trainingClassService.findAlreadyEvaluated(TCCommond);
			for (BaseUserBean user : userList) {
				List<QuestionnaireValidCommond> excel = new ArrayList<QuestionnaireValidCommond>();
				ExportQuestionnaireBean export = new ExportQuestionnaireBean();
				ExportClassQuestionnaireSheet ECQSheet = new ExportClassQuestionnaireSheet();
				QuestionnaireValidCommond exportClassQuestionnaireBean = new QuestionnaireValidCommond();
				StudentInfo studentInfo = new StudentInfo();
				studentInfo.setUserId(user.getUserID());
				studentInfo.setUserName(user.getUserName());
				// 构建调查问卷
				PaperInfo pageInfo = questionnaireService.createQuestionnaireInfo(commond);
				// 获取答案信息，如果存在用户提交的信息获取该信息，否则获取暂存的答卷信息
				UserAnswerLinkQueryCommond queryCommond = new UserAnswerLinkQueryCommond();
				queryCommond.setSearchQuestionnaireId(commond.getQuestionnaireId());
				queryCommond.setSearchUserId(user.getUserID());
				Map<String, List<String>> questionAnswerMap = new LinkedHashMap<String, List<String>>();
				QuestionnaireQueryCommond questionnaireQueryCommond = new QuestionnaireQueryCommond();
				questionnaireQueryCommond.setSearchQuestionnaireId(commond.getQuestionnaireId());
				questionnaireQueryCommond.setSearchUserId(user.getUserID());
				questionnaireQueryCommond.setSearchClassId(commond.getClassId());
				if (questionnaireService.isJoinQuestionnaire(questionnaireQueryCommond)) {
					queryCommond.setSearchClassId(commond.getClassId());
					questionAnswerMap = userAnswerLinkService.queryUserAnswer(queryCommond);
				}

				pageInfo = this.updateQuestionnaireAnswerInfo(pageInfo, questionAnswerMap);

				pageInfo.setSelectProblemInfoGroup(questionnaireService.ExportProblemSets(pageInfo.getSelectProblemInfo()));
				// 查询班级信息
				TrainingClassValidCommond co = trainingClassService.find(commond.getClassId());
				StudentPageInfo studentPageInfo = new StudentPageInfo();
				studentPageInfo.setPageInfo(pageInfo);
				studentPageInfo.setStudentInfo(studentInfo);
				studentPageInfo.setToken(token.saveToken(request));
				// 存放班级信息
				commond.setClassName(co.getClassName());// 班级名称
				commond.setMinistrieName(co.getMinistrieName());// 承办部委
				commond.setBeginDateStr(co.getBeginDateStr());// 开班时间
				commond.setEndDateStr(co.getEndDateStr());// 结班时间
				commond.setStudentPageInfo(studentPageInfo);

				// 存放结果
				BeanUtils.copyProperties(commond, exportClassQuestionnaireBean);
				excel.add(exportClassQuestionnaireBean);
				List<QuestionnaireValidCommond> exportClassQuestionnaireBeanList = new ArrayList<QuestionnaireValidCommond>();
				exportClassQuestionnaireBeanList.add(exportClassQuestionnaireBean);
				export.setExportClassQuestionnaireBeanList(exportClassQuestionnaireBeanList);
				ECQSheet = new ExportClassQuestionnaireSheet();
				ECQSheet.setExportObject(export);
				ECQSheet.setSheetName(user.getLoginID());
				ECQSheet.setExprotFormatName(user.getUserName());
				sheetList.add(ECQSheet);
			}
			Sheet[] sheetArray = new Sheet[sheetList.size()];// 导出Excel的Sheet集合
			for (int i = 0; i < sheetList.size(); i++) {
				sheetArray[i] = sheetList.get(i);
			}
			if (sheetArray.length > 0) {
				try {
					response.reset();
					response.setContentType("application/x-msdownload");
					HSSFWorkbook xls;
					if (commond.getAssessExport() == 1) {
						xls = exportOriginalCollect(sheetArray);
						response.setHeader("Content-Disposition", "attachment; filename=" + new String((commond.getClassName()+"-原始汇总表").getBytes("gb2312"), "ISO-8859-1") + ".xls");
					} else {
						xls = exportPaperToXls(sheetArray);
						response.setHeader("Content-Disposition", "attachment; filename=" + new String((commond.getClassName()+"-学员评估详情表").getBytes("gb2312"), "ISO-8859-1") + ".xls");
					}
					ServletOutputStream outStream = null;
					outStream = response.getOutputStream();
					xls.write(outStream);
					outStream.close();
					resultState.setState(ResultState.RESULT_STATE_SUCCESS);
					resultState.setMessage("导出成功!");
				} catch (Exception e1) {
					e1.printStackTrace();
					resultState.setState(ResultState.RESULT_STATE_FAIL);
					resultState.setMessage("导出失败！!");
				}
			} else {
				resultState.setState(ResultState.RESULT_STATE_FAIL);
				resultState.setMessage("暂无数据!");
				response.setCharacterEncoding("GB2312"); 
				PrintWriter pw=response.getWriter();
				pw.write("<script>alert('暂无数据');window.opener='';window.open('', '_self', '');window.close();</script>");
				pw.close();
			}
		} else {
			resultState.setState(ResultState.RESULT_STATE_FAIL);
			resultState.setMessage("信息不全!");
		}
	}
	
	/**
	 * 培训班详情导出
	 * @param commond
	 * @param request
	 * @return
	 * @throws Exception
	 * @author RongSl
	 * @date 2016-09-21
	 */
	@RequestMapping("/exportClassOriginalCollect")
	public void exportClassOriginalCollect(@ModelAttribute("resultList") QuestionnaireQueryCommond queryCommond, HttpServletRequest request, HttpServletResponse response,
			@ModelAttribute("resultState") ResultState resultState) throws Exception {
		resultState.setState(ResultState.RESULT_STATE_FAIL);// 默认失败
		List<Sheet> sheetList = new ArrayList<Sheet>();
		List<BaseUserBean> userList = null;
		TrainingClassQueryCommond TCCommond = new TrainingClassQueryCommond();
		if (PropertyUtil.objectNotEmpty(queryCommond.getSearchClassIds())) {
			String searchClassIds[]=queryCommond.getSearchClassIds()[0].split(",");
			String searchQuestionnaireIds[]=queryCommond.getSearchQuestionnaireIds()[0].split(",");
//			for(String ids:searchClassIds){
//				
//			}
			QuestionnaireValidCommond commond=new QuestionnaireValidCommond();
			commond.setClassId(searchClassIds[0]);
			commond.setQuestionnaireId(searchQuestionnaireIds[0]);
			TCCommond.setSearchClassId(commond.getClassId());
			TCCommond.setSearchQuestionnaireId(commond.getQuestionnaireId());
			TCCommond.setAnswerUserStatus(1);
			TCCommond.setPage(-1);
			userList = trainingClassService.findAnswerUser(TCCommond);
			for (BaseUserBean user : userList) {
				List<QuestionnaireValidCommond> excel = new ArrayList<QuestionnaireValidCommond>();
				ExportQuestionnaireBean export = new ExportQuestionnaireBean();
				ExportClassQuestionnaireSheet ECQSheet = new ExportClassQuestionnaireSheet();
				QuestionnaireValidCommond exportClassQuestionnaireBean = new QuestionnaireValidCommond();
				StudentInfo studentInfo = new StudentInfo();
				studentInfo.setUserId(user.getUserID());
				studentInfo.setUserName(user.getUserName());
				// 构建调查问卷
				PaperInfo pageInfo = questionnaireService.createQuestionnaireInfo(commond);
				// 获取答案信息，如果存在用户提交的信息获取该信息，否则获取暂存的答卷信息
				UserAnswerLinkQueryCommond qCommond = new UserAnswerLinkQueryCommond();
				qCommond.setSearchQuestionnaireId(commond.getQuestionnaireId());
				qCommond.setSearchUserId(user.getUserID());
				Map<String, List<String>> questionAnswerMap = new LinkedHashMap<String, List<String>>();
				QuestionnaireQueryCommond questionnaireQueryCommond = new QuestionnaireQueryCommond();
				questionnaireQueryCommond.setSearchQuestionnaireId(commond.getQuestionnaireId());
				questionnaireQueryCommond.setSearchUserId(user.getUserID());
				questionnaireQueryCommond.setSearchClassId(commond.getClassId());
				if (questionnaireService.isJoinQuestionnaire(questionnaireQueryCommond)) {
					qCommond.setSearchClassId(commond.getClassId());
					questionAnswerMap = userAnswerLinkService.queryUserAnswer(qCommond);
				}
				
				pageInfo = this.updateQuestionnaireAnswerInfo(pageInfo, questionAnswerMap);
				
				pageInfo.setSelectProblemInfoGroup(questionnaireService.ExportProblemSets(pageInfo.getSelectProblemInfo()));
				// 查询班级信息
				TrainingClassValidCommond co = trainingClassService.find(commond.getClassId());
				StudentPageInfo studentPageInfo = new StudentPageInfo();
				studentPageInfo.setPageInfo(pageInfo);
				studentPageInfo.setStudentInfo(studentInfo);
				studentPageInfo.setToken(token.saveToken(request));
				// 存放班级信息
				commond.setClassName(co.getClassName());// 班级名称
				commond.setMinistrieName(co.getMinistrieName());// 承办部委
				commond.setBeginDateStr(co.getBeginDateStr());// 开班时间
				commond.setEndDateStr(co.getEndDateStr());// 结班时间
				commond.setStudentPageInfo(studentPageInfo);
				
				// 存放结果
				BeanUtils.copyProperties(commond, exportClassQuestionnaireBean);
				excel.add(exportClassQuestionnaireBean);
				List<QuestionnaireValidCommond> exportClassQuestionnaireBeanList = new ArrayList<QuestionnaireValidCommond>();
				exportClassQuestionnaireBeanList.add(exportClassQuestionnaireBean);
				export.setExportClassQuestionnaireBeanList(exportClassQuestionnaireBeanList);
				ECQSheet = new ExportClassQuestionnaireSheet();
				ECQSheet.setExportObject(export);
				ECQSheet.setSheetName(user.getLoginID());
				sheetList.add(ECQSheet);
			}
			Sheet[] sheetArray = new Sheet[sheetList.size()];// 导出Excel的Sheet集合
			for (int i = 0; i < sheetList.size(); i++) {
				sheetArray[i] = sheetList.get(i);
			}
			if (sheetArray.length > 0) {
				try {
					response.reset();
					response.setContentType("application/x-msdownload");
					HSSFWorkbook xls;
					xls = exportClassOriginalCollectUtil(sheetArray);
					response.setHeader("Content-Disposition", "attachment; filename=" + new String((commond.getClassName()+"-培训班汇总表").getBytes("gb2312"), "ISO-8859-1") + ".xls");
					ServletOutputStream outStream = null;
					outStream = response.getOutputStream();
					xls.write(outStream);
					outStream.close();
					resultState.setState(ResultState.RESULT_STATE_SUCCESS);
					resultState.setMessage("导出成功!");
				} catch (Exception e1) {
					e1.printStackTrace();
					resultState.setState(ResultState.RESULT_STATE_FAIL);
					resultState.setMessage("导出失败！!");
				}
			} else {
				resultState.setState(ResultState.RESULT_STATE_FAIL);
				resultState.setMessage("暂无数据!");
				response.setCharacterEncoding("GB2312"); 
				PrintWriter pw=response.getWriter();
				pw.write("<script>alert('暂无数据');window.opener='';window.open('', '_self', '');window.close();</script>");
				pw.close();
			}
		} else {//导出全部班级评估问卷
			resultState.setState(ResultState.RESULT_STATE_FAIL);
			resultState.setMessage("信息不全!");
		}
	}

	/**
	 * 学员评估详情
	 * 
	 * @param sheetArray
	 * @return HSSFWorkbook
	 * @author RongSl
	 * @date 2016-02-24
	 */
	public HSSFWorkbook exportPaperToXls(Sheet[] sheetArray) {

		// 第一步，创建一个webbook，对应一个Excel文件
		HSSFWorkbook wb = new HSSFWorkbook();
		// 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
		HSSFSheet sheet;
		// 调查问卷表
		QuestionnaireValidCommond questionnaireValidCommond = null;
		// 试卷信息
		PaperInfo pageInfo = null;
		// 单选题分题组
		List<List<SelectProblemInfo>> selectProblemInfoGroup = null;
		// 单选题组
		List<SelectProblemInfo> selectProblemIn = null;
		// 多选题组
		List<SelectProblemInfo> multipleSelectProblemInfo = null;
		// 问答题组
		List<EssayQuestionInfo> essayQuestionInfo = null;
		// 单选&&多选题Bean
		SelectProblemInfo selectProblemInfo = null;
		// 问答题Bean
		EssayQuestionInfo essayQuestion = null;
		// 选项实体Bean
		ItemOption IOption = null;
		for (int i = 0; i < sheetArray.length; i++) {

			// excel分页结果表
			ExportClassQuestionnaireSheet exportClassQuestionnaireSheet = new ExportClassQuestionnaireSheet();
			exportClassQuestionnaireSheet = (ExportClassQuestionnaireSheet) sheetArray[i];
			questionnaireValidCommond = ((ExportQuestionnaireBean) exportClassQuestionnaireSheet.getExportObject()).getExportClassQuestionnaireBeanList().get(0);
			pageInfo = questionnaireValidCommond.getStudentPageInfo().getPageInfo();
			selectProblemInfoGroup = pageInfo.getSelectProblemInfoGroup();
			multipleSelectProblemInfo = pageInfo.getMultipleSelectProblemInfo();
			essayQuestionInfo = pageInfo.getEssayQuestionInfo();

			sheet = wb.createSheet(exportClassQuestionnaireSheet.getSheetName());
			// 第三步，在sheet中添加表头第0行
			HSSFRow row = null;

			// 设置字体样式
			HSSFFont font = wb.createFont();
			font.setFontName("黑体");
			font.setFontHeightInPoints((short) 18);// 设置字体大小
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 粗体显示

			HSSFFont font2 = wb.createFont();
			font.setFontName("楷体");
			font2.setFontHeightInPoints((short) 13);// 设置字体大小

			HSSFFont font3 = wb.createFont();// 题组样式
			font.setFontName("微软雅黑");
			font3.setFontHeightInPoints((short) 15);// 设置字体大小

			// 设置单元格样式
			HSSFCellStyle style0 = wb.createCellStyle();// 标题样式
			style0.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 居中对齐
			style0.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
			style0.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style0.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			style0.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			style0.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			style0.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			style0.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style0.setFillForegroundColor(HSSFColor.WHITE.index);// 单元格背景色
			style0.setFont(font);
			HSSFCellStyle style1 = wb.createCellStyle();// 单选样式
			style1.setAlignment(HSSFCellStyle.ALIGN_LEFT); // 创建一个居中格式
			style1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
			style1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style1.setFillForegroundColor(HSSFColor.LIME.index);// 单元格背景色
			style1.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			style1.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			style1.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			style1.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			style1.setFont(font2);
			HSSFCellStyle style2 = wb.createCellStyle();// 多选样式
			style2.setAlignment(HSSFCellStyle.ALIGN_LEFT); // 创建一个居中格式
			style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
			style2.setFillForegroundColor(HSSFColor.CORNFLOWER_BLUE.index);// 单元格背景色
			style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			style2.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			style2.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			style2.setFont(font2);
			HSSFCellStyle style3 = wb.createCellStyle();
			style3.setAlignment(HSSFCellStyle.ALIGN_LEFT); // 创建一个居中格式
			style3.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
			style3.setFillForegroundColor(HSSFColor.GOLD.index);// 单元格背景色
			style3.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style3.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			style3.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			style3.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			style3.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			style3.setFont(font2);

			HSSFCellStyle style4 = wb.createCellStyle();
			style4.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
			style4.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
			style4.setFillForegroundColor(HSSFColor.SKY_BLUE.index);// 单元格背景色
			style4.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style4.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			style4.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			style4.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			style4.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			style4.setFont(font3);

			int questionsProblemSetsHeightOne = 1;// 起始行
			int questionsProblemSetsHeightTwo = 0;// 终止行

			sheet.setDefaultRowHeight((short) 432);// 默认单元格高度

			int width0 = 5;
			int width1 = 5;
			int width2 = 5;

			// 第四步，创建单元格，并设置值表头 设置表头居中
			row = sheet.createRow(0);
			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 1));
			HSSFCell cell = row.createCell(0);
			cell.setCellValue("评估项目");
			cell.setCellStyle(style0);
			cell = row.createCell(2);
			cell.setCellValue("评分");
			cell.setCellStyle(style0);
			for (int k = 0; k < selectProblemInfoGroup.size(); k++) {// 遍历单选题组
				selectProblemIn = selectProblemInfoGroup.get(k);
				questionsProblemSetsHeightTwo += selectProblemIn.size();
				row = sheet.createRow(questionsProblemSetsHeightOne);
				sheet.addMergedRegion(new CellRangeAddress(questionsProblemSetsHeightOne, questionsProblemSetsHeightTwo, 0, 0));
				for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题
					selectProblemInfo = selectProblemIn.get(j);
					row = sheet.createRow(questionsProblemSetsHeightOne);
					questionsProblemSetsHeightOne++;
					cell = row.createCell(0);
					cell.setCellValue(selectProblemInfo.getQuestionsProblemSets());
					if (selectProblemInfo.getQuestionsProblemSets().length() > width0) {
						width0 = selectProblemInfo.getQuestionsProblemSets().length();
					}
					cell.setCellStyle(style4);
					cell = row.createCell(1);
					cell.setCellValue(selectProblemInfo.getItemTitle());
					if (selectProblemInfo.getItemTitle().length() > width1) {
						width1 = selectProblemInfo.getItemTitle().length();
					}
					cell.setCellStyle(style1);
					cell = row.createCell(2);
					cell.setCellValue("未选择");
					for (ItemOption option : selectProblemInfo.getItemOption()) {
						if (option.getIsSelect() == true) {
							cell.setCellValue(option.getOption());
							if (option.getOption().length() > width2) {
								width2 = option.getOption().length();
							}
						}
					}
					cell.setCellStyle(style1);
				}
			}
			for (int k = 0; k < multipleSelectProblemInfo.size(); k++) {// 遍历多选题
				selectProblemInfo = multipleSelectProblemInfo.get(k);
				questionsProblemSetsHeightTwo += selectProblemInfo.getItemOption().size();// 终止行
				sheet.addMergedRegion(new CellRangeAddress(questionsProblemSetsHeightOne, questionsProblemSetsHeightTwo, 0, 0));
				for (int j = 0; j < selectProblemInfo.getItemOption().size(); j++) {
					IOption = selectProblemInfo.getItemOption().get(j);
					row = sheet.createRow(questionsProblemSetsHeightOne);
					questionsProblemSetsHeightOne++;
					cell = row.createCell(0);
					cell.setCellValue(selectProblemInfo.getItemTitle());
					if (selectProblemInfo.getItemTitle().length() > width0) {
						width0 = selectProblemInfo.getItemTitle().length();
					}
					cell.setCellStyle(style4);
					cell = row.createCell(1);
					cell.setCellValue(IOption.getOption());
					if (IOption.getOption().length() > width1) {
						width1 = IOption.getOption().length();
					}
					cell.setCellStyle(style2);
					cell = row.createCell(2);
					if (IOption.getIsSelect() == true) {
						cell.setCellValue(1);
						if (IOption.getObjectiveTopic() == 1) {
							if (PropertyUtil.objectNotEmpty(IOption.getOptionAnswer()) && IOption.getOptionAnswer().trim().length() > 0) {
								cell.setCellValue(IOption.getOptionAnswer());
								if (IOption.getOptionAnswer().length() > width2) {
									width2 = IOption.getOptionAnswer().length();
								}
							} else {
								cell.setCellValue("未填写");
							}
						}
					} else {
						cell.setCellValue(0);
					}
					cell.setCellStyle(style2);
				}
			}
			for (int k = 0; k < essayQuestionInfo.size(); k++) {// 遍历问答题
				essayQuestion = essayQuestionInfo.get(k);
				row = sheet.createRow(questionsProblemSetsHeightOne);
				questionsProblemSetsHeightTwo++;
				sheet.addMergedRegion(new CellRangeAddress(questionsProblemSetsHeightOne, questionsProblemSetsHeightTwo, 0, 1));
				questionsProblemSetsHeightOne++;
				for (int c = 0; c < 2; c++) {
					cell = row.createCell(c);
					cell.setCellStyle(style4);
				}
				cell = row.createCell(0);
				cell.setCellValue(essayQuestion.getQuestionName());
				if (essayQuestion.getQuestionName().length() > width0) {
					width0 = essayQuestion.getQuestionName().length();
				}
				cell.setCellStyle(style4);
				cell = row.createCell(2);
				if (PropertyUtil.objectNotEmpty(essayQuestion.getQuestionAnswer())) {
					cell.setCellValue(essayQuestion.getQuestionAnswer());
					if (essayQuestion.getQuestionAnswer().length() > width2) {
						width2 = essayQuestion.getQuestionAnswer().length();
					}
				} else {
					cell.setCellValue("未填写");
				}
				cell.setCellStyle(style3);
			}

			sheet.setColumnWidth(0, width0 * 256 * 3);
			sheet.setColumnWidth(1, width1 * 256 * 3);
			sheet.setColumnWidth(2, width2 * 256 * 2);

		}
		return wb;
	}

	/**
	 * 原始总汇导出
	 * @param sheetArray
	 * @return HSSFWorkbook
	 * @author RongSl
	 * @date 2016-02-29
	 */
	public HSSFWorkbook exportOriginalCollect(Sheet[] sheetArray) {
		// 第一步，创建一个webbook，对应一个Excel文件
		HSSFWorkbook wb = new HSSFWorkbook();
		// 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
		HSSFSheet sheet;
		// 调查问卷表
		QuestionnaireValidCommond questionnaireValidCommond = null;
		// 试卷信息
		PaperInfo pageInfo = null;
		// 单选题分题组
		List<List<SelectProblemInfo>> selectProblemInfoGroup = null;
		// 单选题组
		List<SelectProblemInfo> selectProblemIn = null;
		// 多选题组
		List<SelectProblemInfo> multipleSelectProblemInfo = null;
		// 问答题组
		List<EssayQuestionInfo> essayQuestionInfo = null;
		// 单选&&多选题Bean
		SelectProblemInfo selectProblemInfo = null;
		// 问答题Bean
		EssayQuestionInfo essayQuestion = null;
		// 选项实体Bean
		ItemOption IOption = null;

		List<ScoreStatisticsBean> scoreList = new ArrayList<ScoreStatisticsBean>();
		// List<RadioStatisticsBean> radioList = new
		// ArrayList<RadioStatisticsBean>();
		List<MCQStatisticsBean> MCQList = new ArrayList<MCQStatisticsBean>();

		// 设置字体样式
		HSSFFont font = wb.createFont();
		font.setFontName("黑体");
		font.setFontHeightInPoints((short) 14);// 设置字体大小
		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 粗体显示

		HSSFFont font2 = wb.createFont();
		font.setFontName("楷体");
		font2.setFontHeightInPoints((short) 12);// 设置字体大小

		HSSFFont font3 = wb.createFont();// 题组样式
		font.setFontName("微软雅黑");
		font3.setFontHeightInPoints((short) 10);// 设置字体大小

		// 设置单元格样式
		HSSFCellStyle style0 = wb.createCellStyle();// 标题样式
		style0.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 居中对齐
		style0.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style0.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style0.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style0.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style0.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style0.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style0.setFillForegroundColor(HSSFColor.SKY_BLUE.index);// 单元格背景色
		style0.setFont(font);

		HSSFCellStyle style1 = wb.createCellStyle();// 单选样式
		style1.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 创建一个居中格式
		style1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style1.setFillForegroundColor(HSSFColor.LIME.index);// 单元格背景色
		style1.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style1.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style1.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style1.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style1.setFont(font2);

		HSSFCellStyle style2 = wb.createCellStyle();
		style2.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 创建一个居中格式
		style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style2.setFillForegroundColor(HSSFColor.CORNFLOWER_BLUE.index);// 单元格背景色
		style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style2.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style2.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style2.setFont(font2);

		HSSFCellStyle style3 = wb.createCellStyle();
		style3.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 创建一个居中格式
		style3.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style3.setFillForegroundColor(HSSFColor.GOLD.index);// 单元格背景色
		style3.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style3.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style3.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style3.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style3.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style3.setFont(font2);

		HSSFCellStyle style4 = wb.createCellStyle();// 编号样式
		style4.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // 创建一个居中格式
		style4.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style4.setFillForegroundColor(HSSFColor.SKY_BLUE.index);// 单元格背景色
		style4.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style4.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style4.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style4.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style4.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style4.setFont(font3);

		HSSFCellStyle style5 = wb.createCellStyle();// 标题样式
		style5.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 居中对齐
		style5.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style5.setFillForegroundColor(HSSFColor.YELLOW.index);// 单元格背景色
		style5.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style5.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style5.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style5.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style5.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style5.setFont(font3);

		HSSFCellStyle style6 = wb.createCellStyle();// 标题样式
		style6.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 居中对齐
		style6.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style6.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style6.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style6.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style6.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style6.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style6.setFillForegroundColor(HSSFColor.ORANGE.index);// 单元格背景色
		style6.setFont(font);

		// 第三步，在sheet中添加表头第0行
		HSSFRow row = null;

		sheet = wb.createSheet("原始汇总");
		sheet.setDefaultRowHeight((short) 432);// 默认单元格高度
		int RowCount = sheetArray.length + 2;// 总行;
		HSSFRow row2 = sheet.createRow(RowCount + 1);
		HSSFCell cell2 = null;
		for (int g = 0; g < RowCount; g++) {
			row = sheet.createRow(g);
			row2 = sheet.createRow(g);
		}
		int o = 0;
		for (int i = 0; i < sheetArray.length; i++) {

			int questionsProblemSetsRowTwo = sheetArray.length + 2;// 总行

			HSSFCell cell;

			a: for (; o < questionsProblemSetsRowTwo; o++) {

				ExportClassQuestionnaireSheet exportClassQuestionnaireSheet = new ExportClassQuestionnaireSheet();
				exportClassQuestionnaireSheet = (ExportClassQuestionnaireSheet) sheetArray[i];
				questionnaireValidCommond = ((ExportQuestionnaireBean) exportClassQuestionnaireSheet.getExportObject()).getExportClassQuestionnaireBeanList().get(0);
				pageInfo = questionnaireValidCommond.getStudentPageInfo().getPageInfo();
				selectProblemInfoGroup = pageInfo.getSelectProblemInfoGroup();
				multipleSelectProblemInfo = pageInfo.getMultipleSelectProblemInfo();
				essayQuestionInfo = pageInfo.getEssayQuestionInfo();
				row = sheet.createRow(o);
				if (o == 0) { // 打印大标题
					int questionsProblemSetsCosOne = 1;// 起始列
					int questionsProblemSetsCosTwo = 0;// 终止列
					row = sheet.createRow(0);
					sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
					cell = row.createCell(0);
					cell.setCellValue("编号/姓名");
					cell.setCellStyle(style6);
					for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
						selectProblemIn = selectProblemInfoGroup.get(k);
						questionsProblemSetsCosTwo += selectProblemIn.size();
						for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题标题
							selectProblemInfo = selectProblemIn.get(j);
							sheet.addMergedRegion(new CellRangeAddress(i, i, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
							cell = row.createCell(questionsProblemSetsCosOne);
							cell.setCellValue(selectProblemIn.get(j).getQuestionsProblemSets());
							cell.setCellStyle(style1);
							questionsProblemSetsCosOne++;
						}
					}
					for (int k = 0; k < multipleSelectProblemInfo.size(); k++) {// 遍历多选题标题
						selectProblemInfo = multipleSelectProblemInfo.get(k);
						questionsProblemSetsCosTwo += selectProblemInfo.getItemOption().size();// 终止列
						sheet.addMergedRegion(new CellRangeAddress(i, i, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
						cell = row.createCell(questionsProblemSetsCosOne);
						cell.setCellValue(selectProblemInfo.getItemTitle());
						cell.setCellStyle(style2);
						questionsProblemSetsCosOne += selectProblemInfo.getItemOption().size();// 终止列
					}
					for (int k = 0; k < essayQuestionInfo.size(); k++) {// 遍历问答题
						essayQuestion = essayQuestionInfo.get(k);
						questionsProblemSetsCosTwo++;
						sheet.addMergedRegion(new CellRangeAddress(i, i + 1, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
						cell = row.createCell(questionsProblemSetsCosOne);
						cell.setCellValue(essayQuestion.getQuestionName());
						cell.setCellStyle(style3);
						questionsProblemSetsCosOne++;
					}

					try {
						UserAnswerLinkQueryCommond queryCommond = new UserAnswerLinkQueryCommond();
						queryCommond.setSearchQuestionnaireId(questionnaireValidCommond.getQuestionnaireId());
						queryCommond.setSearchClassId(questionnaireValidCommond.getClassId());
						scoreList = userAnswerLinkService.findScoreRadioList(queryCommond); // 数值型单选题统计集合
						// radioList =
						// userAnswerLinkService.findTextRadioList(queryCommond);
						// // 文字型单选题统计集合
						MCQList = userAnswerLinkService.findMCQList(queryCommond); // 多选题统计集合
					} catch (Exception e) {
						e.printStackTrace();
						System.out.println("单选题查询出错。");
					}

				} else if (o == 1) {// 打印小标题
					int questionsProblemSetsCosOne = 1;// 起始列
					row = sheet.createRow(o);
					for (int k = 0; k < selectProblemInfoGroup.size(); k++) {// 遍历单选题组
						selectProblemIn = selectProblemInfoGroup.get(k);
						for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题
							selectProblemInfo = selectProblemIn.get(j);
							cell = row.createCell(questionsProblemSetsCosOne);
							cell.setCellValue(selectProblemIn.get(j).getItemTitle());
							cell.setCellStyle(style1);
							questionsProblemSetsCosOne++;
						}
					}
					for (int k = 0; k < multipleSelectProblemInfo.size(); k++) {// 遍历多选题
						selectProblemInfo = multipleSelectProblemInfo.get(k);
						for (int j = 0; j < selectProblemInfo.getItemOption().size(); j++) {
							IOption = selectProblemInfo.getItemOption().get(j);
							cell = row.createCell(questionsProblemSetsCosOne);
							cell.setCellValue(IOption.getOption());
							cell.setCellStyle(style2);
							questionsProblemSetsCosOne++;
						}
					}
					for (int k = 0; k < essayQuestionInfo.size(); k++) {// 遍历问答题
						essayQuestion = essayQuestionInfo.get(k);
						cell = row.createCell(questionsProblemSetsCosOne);
						questionsProblemSetsCosOne++;
						cell.setCellStyle(style3);
					}
				} else {// 打印分数
					int questionsProblemSetsCosOne = 0;// 起始列
					row = sheet.createRow(o);
					cell = row.createCell(questionsProblemSetsCosOne);
					cell.setCellValue(sheetArray[o - 2].getSheetName()+"/"+sheetArray[o - 2].getExprotFormatName());
					cell.setCellStyle(style0);
					for (int k = 0; k < selectProblemInfoGroup.size(); k++) {// 遍历单选题组
						selectProblemIn = selectProblemInfoGroup.get(k);
						for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题
							questionsProblemSetsCosOne++;
							selectProblemInfo = selectProblemIn.get(j);
							cell = row.createCell(questionsProblemSetsCosOne);
							cell.setCellValue("未选择");
							for (ItemOption option : selectProblemInfo.getItemOption()) {
								if (option.getIsSelect() == true) {
									cell.setCellValue(option.getOption());
								}
							}
							cell.setCellStyle(style4);
						}
					}
					questionsProblemSetsCosOne++;
					for (int k = 0; k < multipleSelectProblemInfo.size(); k++) {// 遍历多选题
						selectProblemInfo = multipleSelectProblemInfo.get(k);
						for (int j = 0; j < selectProblemInfo.getItemOption().size(); j++) {
							IOption = selectProblemInfo.getItemOption().get(j);
							cell = row.createCell(questionsProblemSetsCosOne);
							if (IOption.getIsSelect() == true) {
								cell.setCellValue(1);
								if (IOption.getObjectiveTopic() == 1) {
									if (PropertyUtil.objectNotEmpty(IOption.getOptionAnswer()) && IOption.getOptionAnswer().trim().length() > 0) {
										cell.setCellValue(IOption.getOptionAnswer());
									} else {
										cell.setCellValue("未填写");
									}
								}
							} else {
								cell.setCellValue(0);
							}
							cell.setCellStyle(style4);
							questionsProblemSetsCosOne++;
						}
					}
					for (int k = 0; k < essayQuestionInfo.size(); k++) {// 遍历问答题
						essayQuestion = essayQuestionInfo.get(k);
						cell = row.createCell(questionsProblemSetsCosOne);
						if (PropertyUtil.objectNotEmpty(essayQuestion.getQuestionAnswer())) {
							cell.setCellValue(essayQuestion.getQuestionAnswer());
						} else {
							cell.setCellValue("未填写");
						}
						cell.setCellStyle(style4);
						questionsProblemSetsCosOne++;
					}
					o++;
					break a;
				}
			}
			for (int z = 0; z <= 30; z++) {
				sheet.setColumnWidth(z, 8000);
			}
		}
		// 总分
		int q = o;
		for (; q <= o + 7; q++) {
			int b = 0;
			row2 = sheet.createRow(q);
			switch (q - o) {
			case 0:
				cell2 = row2.createCell(0);
				cell2.setCellValue("单项总分");
				cell2.setCellStyle(style5);
				for (int i = 0; i < sheetArray.length; i++) {

					int questionsProblemSetsRowTwo = sheetArray.length + 2;// 总行

					for (; b < questionsProblemSetsRowTwo; b++) {

						ExportClassQuestionnaireSheet exportClassQuestionnaireSheet = new ExportClassQuestionnaireSheet();
						exportClassQuestionnaireSheet = (ExportClassQuestionnaireSheet) sheetArray[i];
						questionnaireValidCommond = ((ExportQuestionnaireBean) exportClassQuestionnaireSheet.getExportObject()).getExportClassQuestionnaireBeanList().get(0);
						pageInfo = questionnaireValidCommond.getStudentPageInfo().getPageInfo();
						selectProblemInfoGroup = pageInfo.getSelectProblemInfoGroup();
						multipleSelectProblemInfo = pageInfo.getMultipleSelectProblemInfo();
						essayQuestionInfo = pageInfo.getEssayQuestionInfo();
						int questionsProblemSetsCosOne = 1;// 起始列

						for (int k = 0; k < selectProblemInfoGroup.size(); k++) {// 遍历单选题组
							selectProblemIn = selectProblemInfoGroup.get(k);
							for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题
								selectProblemInfo = selectProblemIn.get(j);
								cell2 = row2.createCell(questionsProblemSetsCosOne);
								cell2.setCellValue("");
								for (ScoreStatisticsBean bean : scoreList) {
									if (bean.getQuestionId().equals(selectProblemInfo.getItemId())) {
										cell2.setCellValue(bean.getUnitermSum());
										break;
									}
								}
								if(selectProblemInfo.getIsScoreType().equals(1)){
									cell2.setCellStyle(style5);
									questionsProblemSetsCosOne++;
								}
							}
						}

						for (int k = 0; k < multipleSelectProblemInfo.size(); k++) {// 遍历多选题
							selectProblemInfo = multipleSelectProblemInfo.get(k);
							for (int j = 0; j < selectProblemInfo.getItemOption().size(); j++) {
								IOption = selectProblemInfo.getItemOption().get(j);
								cell2 = row2.createCell(questionsProblemSetsCosOne);
								for (MCQStatisticsBean bean : MCQList) {
									if (bean.getOptionNum().toString().equals(IOption.getOptionNum().toString()) && bean.getQuestionId().equals(selectProblemInfo.getItemId())) {
										cell2.setCellValue(bean.getSelectedNum());
										cell2.setCellStyle(style5);
									}
								}
								questionsProblemSetsCosOne++;
							}
						}
					}
				}
				break;
			case 1:
				cell2 = row2.createCell(0);
				cell2.setCellValue("单项平均分");
				cell2.setCellStyle(style5);
				for (int i = 0; i < sheetArray.length; i++) {

					int questionsProblemSetsRowTwo = sheetArray.length + 2;// 总行

					for (; b < questionsProblemSetsRowTwo; b++) {

						ExportClassQuestionnaireSheet exportClassQuestionnaireSheet = new ExportClassQuestionnaireSheet();
						exportClassQuestionnaireSheet = (ExportClassQuestionnaireSheet) sheetArray[i];
						questionnaireValidCommond = ((ExportQuestionnaireBean) exportClassQuestionnaireSheet.getExportObject()).getExportClassQuestionnaireBeanList().get(0);
						pageInfo = questionnaireValidCommond.getStudentPageInfo().getPageInfo();
						selectProblemInfoGroup = pageInfo.getSelectProblemInfoGroup();
						multipleSelectProblemInfo = pageInfo.getMultipleSelectProblemInfo();
						essayQuestionInfo = pageInfo.getEssayQuestionInfo();
						int questionsProblemSetsCosOne = 1;// 起始列

						for (int k = 0; k < selectProblemInfoGroup.size(); k++) {// 遍历单选题组
							selectProblemIn = selectProblemInfoGroup.get(k);
							for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题
								selectProblemInfo = selectProblemIn.get(j);
								cell2 = row2.createCell(questionsProblemSetsCosOne);
								cell2.setCellValue("");
								for (ScoreStatisticsBean bean : scoreList) {
									if (bean.getQuestionId().equals(selectProblemInfo.getItemId())) {
										cell2.setCellValue(bean.getUnitermAvg());
										break;
									}
								}
								if(selectProblemInfo.getIsScoreType().equals(1)){
									cell2.setCellStyle(style5);
									questionsProblemSetsCosOne++;
								}
							}
						}
					}
				}
				break;
			case 2:
				cell2 = row2.createCell(0);
				cell2.setCellValue("类总分");
				cell2.setCellStyle(style5);
				int questionsProblemSetsCosOne = 1;// 起始列
				int questionsProblemSetsCosTwo = 0;// 终止列
				for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
					selectProblemIn = selectProblemInfoGroup.get(k);
					questionsProblemSetsCosTwo += selectProblemIn.size();
					for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题标题
						selectProblemInfo = selectProblemIn.get(j);
						sheet.addMergedRegion(new CellRangeAddress(q, q, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
						cell2 = row2.createCell(questionsProblemSetsCosOne);
						for (ScoreStatisticsBean bean : scoreList) {
							if (bean.getQuestionId().equals(selectProblemInfo.getItemId())) {
								cell2.setCellValue(bean.getTestletSum());
								break;
							}
						}
						if(selectProblemInfo.getIsScoreType().equals(1)){
							cell2.setCellStyle(style5);
							questionsProblemSetsCosOne++;
						}
					}
				}
				break;
			case 3:
				cell2 = row2.createCell(0);
				cell2.setCellValue("类单项平均分");
				cell2.setCellStyle(style5);
				questionsProblemSetsCosOne = 1;// 起始列
				questionsProblemSetsCosTwo = 0;// 终止列
				for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
					selectProblemIn = selectProblemInfoGroup.get(k);
					questionsProblemSetsCosTwo += selectProblemIn.size();
					for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题标题
						selectProblemInfo = selectProblemIn.get(j);
						sheet.addMergedRegion(new CellRangeAddress(q, q, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
						cell2 = row2.createCell(questionsProblemSetsCosOne);
						for (ScoreStatisticsBean bean : scoreList) {
							if (bean.getQuestionId().equals(selectProblemInfo.getItemId())) {
								cell2.setCellValue(bean.getTestletAvg());
								break;
							}
						}
						if(selectProblemInfo.getIsScoreType().equals(1)){
							cell2.setCellStyle(style5);
							questionsProblemSetsCosOne++;
						}
					}
				}
				break;
			case 4:
				cell2 = row2.createCell(0);
				cell2.setCellValue("总项总分");
				cell2.setCellStyle(style5);
				questionsProblemSetsCosOne = 1;// 起始列
				questionsProblemSetsCosTwo = 0;// 终止列
				for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
					//跳过字符型的单选题
					if(selectProblemInfoGroup.get(k).get(0).getIsScoreType().equals(2)){
						continue;
					}
					questionsProblemSetsCosTwo += selectProblemInfoGroup.get(k).size();
				}
				for (int v = 1; v <= questionsProblemSetsCosTwo; v++) {
					cell2 = row2.createCell(v);
					cell2.setCellStyle(style5);
				}
				if(questionsProblemSetsCosTwo!=0){
					sheet.addMergedRegion(new CellRangeAddress(q, q, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
					cell2 = row2.createCell(1);
					if (PropertyUtil.objectNotEmpty(scoreList) && PropertyUtil.objectNotEmpty(scoreList.get(0).getTotalSum())) {
						cell2.setCellValue(scoreList.get(0).getTotalSum());
					}
					cell2.setCellStyle(style5);
				}
				break;
			case 5:
				cell2 = row2.createCell(0);
				cell2.setCellValue("总项平均分");
				cell2.setCellStyle(style5);
				questionsProblemSetsCosOne = 1;// 起始列
				questionsProblemSetsCosTwo = 0;// 终止列
				for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
					//跳过字符型的单选题
					if(selectProblemInfoGroup.get(k).get(0).getIsScoreType().equals(2)){
						continue;
					}
					questionsProblemSetsCosTwo += selectProblemInfoGroup.get(k).size();
				}
				for (int v = 1; v <= questionsProblemSetsCosTwo; v++) {
					cell2 = row2.createCell(v);
					cell2.setCellStyle(style5);
				}
				if(questionsProblemSetsCosTwo!=0){
					sheet.addMergedRegion(new CellRangeAddress(q, q, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
					cell2 = row2.createCell(1);
					if (PropertyUtil.objectNotEmpty(scoreList) && PropertyUtil.objectNotEmpty(scoreList.get(0).getTotalAvg())) {
						cell2.setCellValue(scoreList.get(0).getTotalAvg());
					}
					cell2.setCellStyle(style5);
				}
				break;
			case 6:
				cell2 = row2.createCell(0);
				cell2.setCellValue("总体平均分");
				cell2.setCellStyle(style5);
				questionsProblemSetsCosOne = 1;// 起始列
				questionsProblemSetsCosTwo = 0;// 终止列
				for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
					//跳过字符型的单选题
					if(selectProblemInfoGroup.get(k).get(0).getIsScoreType().equals(2)){
						continue;
					}
					questionsProblemSetsCosTwo += selectProblemInfoGroup.get(k).size();
				}
				for (int v = 1; v <= questionsProblemSetsCosTwo; v++) {
					cell2 = row2.createCell(v);
					cell2.setCellStyle(style5);
				}
				if(questionsProblemSetsCosTwo!=0){
					sheet.addMergedRegion(new CellRangeAddress(q, q, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
					cell2 = row2.createCell(1);
					if (PropertyUtil.objectNotEmpty(scoreList) && PropertyUtil.objectNotEmpty(scoreList.get(0).getAllAvg())) {
						cell2.setCellValue(scoreList.get(0).getAllAvg());
					}
					cell2.setCellStyle(style5);
				}
				break;
			}
		}

		return wb;
	}
	
	/**
	 * 培训班汇总导出
	 * 
	 * @param sheetArray
	 * @return HSSFWorkbook
	 * @author RongSl
	 * @date 2016-09-21
	 */
	public HSSFWorkbook exportClassOriginalCollectUtil(Sheet[] sheetArray) {
		// 第一步，创建一个webbook，对应一个Excel文件
		HSSFWorkbook wb = new HSSFWorkbook();
		// 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
		HSSFSheet sheet;
		// 调查问卷表
		QuestionnaireValidCommond questionnaireValidCommond = null;
		// 试卷信息
		PaperInfo pageInfo = null;
		// 单选题分题组
		List<List<SelectProblemInfo>> selectProblemInfoGroup = null;
		// 单选题组
		List<SelectProblemInfo> selectProblemIn = null;
		// 多选题组
		List<SelectProblemInfo> multipleSelectProblemInfo = null;
		// 问答题组
		List<EssayQuestionInfo> essayQuestionInfo = null;
		// 单选&&多选题Bean
		SelectProblemInfo selectProblemInfo = null;
		// 问答题Bean
		EssayQuestionInfo essayQuestion = null;
		// 选项实体Bean
		ItemOption IOption = null;
		
		List<ScoreStatisticsBean> scoreList = new ArrayList<ScoreStatisticsBean>();
		// List<RadioStatisticsBean> radioList = new
		// ArrayList<RadioStatisticsBean>();
		List<MCQStatisticsBean> MCQList = new ArrayList<MCQStatisticsBean>();
		
		// 设置字体样式
		HSSFFont font = wb.createFont();
		font.setFontName("黑体");
		font.setFontHeightInPoints((short) 14);// 设置字体大小
		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 粗体显示
		
		HSSFFont font2 = wb.createFont();
		font.setFontName("楷体");
		font2.setFontHeightInPoints((short) 12);// 设置字体大小
		
		HSSFFont font3 = wb.createFont();// 题组样式
		font.setFontName("微软雅黑");
		font3.setFontHeightInPoints((short) 10);// 设置字体大小
		
		// 设置单元格样式
		HSSFCellStyle style0 = wb.createCellStyle();// 标题样式
		style0.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 居中对齐
		style0.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style0.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style0.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style0.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style0.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style0.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style0.setFillForegroundColor(HSSFColor.SKY_BLUE.index);// 单元格背景色
		style0.setFont(font);
		
		HSSFCellStyle style1 = wb.createCellStyle();// 单选样式
		style1.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 创建一个居中格式
		style1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style1.setFillForegroundColor(HSSFColor.LIME.index);// 单元格背景色
		style1.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style1.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style1.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style1.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style1.setFont(font2);
		
		HSSFCellStyle style2 = wb.createCellStyle();
		style2.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 创建一个居中格式
		style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style2.setFillForegroundColor(HSSFColor.CORNFLOWER_BLUE.index);// 单元格背景色
		style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style2.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style2.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style2.setFont(font2);
		
		HSSFCellStyle style3 = wb.createCellStyle();
		style3.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 创建一个居中格式
		style3.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style3.setFillForegroundColor(HSSFColor.GOLD.index);// 单元格背景色
		style3.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style3.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style3.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style3.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style3.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style3.setFont(font2);
		
		HSSFCellStyle style4 = wb.createCellStyle();// 编号样式
		style4.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // 创建一个居中格式
		style4.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style4.setFillForegroundColor(HSSFColor.SKY_BLUE.index);// 单元格背景色
		style4.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style4.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style4.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style4.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style4.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style4.setFont(font3);
		
		HSSFCellStyle style5 = wb.createCellStyle();// 标题样式
		style5.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 居中对齐
		style5.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style5.setFillForegroundColor(HSSFColor.YELLOW.index);// 单元格背景色
		style5.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style5.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style5.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style5.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style5.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style5.setFont(font3);
		
		HSSFCellStyle style6 = wb.createCellStyle();// 标题样式
		style6.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION); // 居中对齐
		style6.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
		style6.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style6.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
		style6.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
		style6.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
		style6.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
		style6.setFillForegroundColor(HSSFColor.ORANGE.index);// 单元格背景色
		style6.setFont(font);
		
		// 第三步，在sheet中添加表头第0行
		HSSFRow row = null;
		
		sheet = wb.createSheet("原始汇总");
		sheet.setDefaultRowHeight((short) 432);// 默认单元格高度
		int RowCount = sheetArray.length + 2;// 总行;
		HSSFRow row2 = sheet.createRow(RowCount + 1);
		HSSFCell cell2 = null;
		for (int g = 0; g < RowCount; g++) {
			row = sheet.createRow(g);
			row2 = sheet.createRow(g);
		}
		int o = 0;
		for (int i = 0; i < sheetArray.length; i++) {
			
			int questionsProblemSetsRowTwo = sheetArray.length + 2;// 总行
			
			HSSFCell cell;
			
			a: for (; o < questionsProblemSetsRowTwo; o++) {
				
				ExportClassQuestionnaireSheet exportClassQuestionnaireSheet = new ExportClassQuestionnaireSheet();
				exportClassQuestionnaireSheet = (ExportClassQuestionnaireSheet) sheetArray[i];
				questionnaireValidCommond = ((ExportQuestionnaireBean) exportClassQuestionnaireSheet.getExportObject()).getExportClassQuestionnaireBeanList().get(0);
				pageInfo = questionnaireValidCommond.getStudentPageInfo().getPageInfo();
				selectProblemInfoGroup = pageInfo.getSelectProblemInfoGroup();
				multipleSelectProblemInfo = pageInfo.getMultipleSelectProblemInfo();
				essayQuestionInfo = pageInfo.getEssayQuestionInfo();
				row = sheet.createRow(o);
				if (o == 0) { // 打印大标题
					int questionsProblemSetsCosOne = 1;// 起始列
					int questionsProblemSetsCosTwo = 0;// 终止列
					row = sheet.createRow(0);
					sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
					cell = row.createCell(0);
					cell.setCellValue("编号");
					cell.setCellStyle(style6);
					for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
						selectProblemIn = selectProblemInfoGroup.get(k);
						questionsProblemSetsCosTwo += selectProblemIn.size();
						for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题标题
							selectProblemInfo = selectProblemIn.get(j);
							sheet.addMergedRegion(new CellRangeAddress(i, i, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
							cell = row.createCell(questionsProblemSetsCosOne);
							cell.setCellValue(selectProblemIn.get(j).getQuestionsProblemSets());
							cell.setCellStyle(style1);
							questionsProblemSetsCosOne++;
						}
					}
					for (int k = 0; k < multipleSelectProblemInfo.size(); k++) {// 遍历多选题标题
						selectProblemInfo = multipleSelectProblemInfo.get(k);
						questionsProblemSetsCosTwo += selectProblemInfo.getItemOption().size();// 终止列
						sheet.addMergedRegion(new CellRangeAddress(i, i, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
						cell = row.createCell(questionsProblemSetsCosOne);
						cell.setCellValue(selectProblemInfo.getItemTitle());
						cell.setCellStyle(style2);
						questionsProblemSetsCosOne += selectProblemInfo.getItemOption().size();// 终止列
					}
					for (int k = 0; k < essayQuestionInfo.size(); k++) {// 遍历问答题
						essayQuestion = essayQuestionInfo.get(k);
						questionsProblemSetsCosTwo++;
						sheet.addMergedRegion(new CellRangeAddress(i, i + 1, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
						cell = row.createCell(questionsProblemSetsCosOne);
						cell.setCellValue(essayQuestion.getQuestionName());
						cell.setCellStyle(style3);
						questionsProblemSetsCosOne++;
					}
					
					try {
						UserAnswerLinkQueryCommond queryCommond = new UserAnswerLinkQueryCommond();
						queryCommond.setSearchQuestionnaireId(questionnaireValidCommond.getQuestionnaireId());
						queryCommond.setSearchClassId(questionnaireValidCommond.getClassId());
						scoreList = userAnswerLinkService.findScoreRadioList(queryCommond); // 数值型单选题统计集合
						// radioList =
						// userAnswerLinkService.findTextRadioList(queryCommond);
						// // 文字型单选题统计集合
						MCQList = userAnswerLinkService.findMCQList(queryCommond); // 多选题统计集合
					} catch (Exception e) {
						e.printStackTrace();
						System.out.println("单选题查询出错。");
					}
					
				} else if (o == 1) {// 打印小标题
					int questionsProblemSetsCosOne = 1;// 起始列
					row = sheet.createRow(o);
					for (int k = 0; k < selectProblemInfoGroup.size(); k++) {// 遍历单选题组
						selectProblemIn = selectProblemInfoGroup.get(k);
						for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题
							selectProblemInfo = selectProblemIn.get(j);
							cell = row.createCell(questionsProblemSetsCosOne);
							cell.setCellValue(selectProblemIn.get(j).getItemTitle());
							cell.setCellStyle(style1);
							questionsProblemSetsCosOne++;
						}
					}
					for (int k = 0; k < multipleSelectProblemInfo.size(); k++) {// 遍历多选题
						selectProblemInfo = multipleSelectProblemInfo.get(k);
						for (int j = 0; j < selectProblemInfo.getItemOption().size(); j++) {
							IOption = selectProblemInfo.getItemOption().get(j);
							cell = row.createCell(questionsProblemSetsCosOne);
							cell.setCellValue(IOption.getOption());
							cell.setCellStyle(style2);
							questionsProblemSetsCosOne++;
						}
					}
					for (int k = 0; k < essayQuestionInfo.size(); k++) {// 遍历问答题
						essayQuestion = essayQuestionInfo.get(k);
						cell = row.createCell(questionsProblemSetsCosOne);
						questionsProblemSetsCosOne++;
						cell.setCellStyle(style3);
					}
				} else {// 打印分数
					int questionsProblemSetsCosOne = 0;// 起始列
					row = sheet.createRow(o);
					cell = row.createCell(questionsProblemSetsCosOne);
					cell.setCellValue(sheetArray[o - 2].getSheetName());
					cell.setCellStyle(style0);
					for (int k = 0; k < selectProblemInfoGroup.size(); k++) {// 遍历单选题组
						selectProblemIn = selectProblemInfoGroup.get(k);
						for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题
							questionsProblemSetsCosOne++;
							selectProblemInfo = selectProblemIn.get(j);
							cell = row.createCell(questionsProblemSetsCosOne);
							cell.setCellValue("未选择");
							for (ItemOption option : selectProblemInfo.getItemOption()) {
								if (option.getIsSelect() == true) {
									cell.setCellValue(option.getOption());
								}
							}
							cell.setCellStyle(style4);
						}
					}
					questionsProblemSetsCosOne++;
					for (int k = 0; k < multipleSelectProblemInfo.size(); k++) {// 遍历多选题
						selectProblemInfo = multipleSelectProblemInfo.get(k);
						for (int j = 0; j < selectProblemInfo.getItemOption().size(); j++) {
							IOption = selectProblemInfo.getItemOption().get(j);
							cell = row.createCell(questionsProblemSetsCosOne);
							if (IOption.getIsSelect() == true) {
								cell.setCellValue(1);
								if (IOption.getObjectiveTopic() == 1) {
									if (PropertyUtil.objectNotEmpty(IOption.getOptionAnswer()) && IOption.getOptionAnswer().trim().length() > 0) {
										cell.setCellValue(IOption.getOptionAnswer());
									} else {
										cell.setCellValue("未填写");
									}
								}
							} else {
								cell.setCellValue(0);
							}
							cell.setCellStyle(style4);
							questionsProblemSetsCosOne++;
						}
					}
					for (int k = 0; k < essayQuestionInfo.size(); k++) {// 遍历问答题
						essayQuestion = essayQuestionInfo.get(k);
						cell = row.createCell(questionsProblemSetsCosOne);
						if (PropertyUtil.objectNotEmpty(essayQuestion.getQuestionAnswer())) {
							cell.setCellValue(essayQuestion.getQuestionAnswer());
						} else {
							cell.setCellValue("未填写");
						}
						cell.setCellStyle(style4);
						questionsProblemSetsCosOne++;
					}
					o++;
					break a;
				}
			}
			for (int z = 0; z <= 30; z++) {
				sheet.setColumnWidth(z, 8000);
			}
		}
		// 总分
		int q = o;
		for (; q <= o + 7; q++) {
			int b = 0;
			row2 = sheet.createRow(q);
			switch (q - o) {
			case 0:
				cell2 = row2.createCell(0);
				cell2.setCellValue("单项总分");
				cell2.setCellStyle(style5);
				for (int i = 0; i < sheetArray.length; i++) {
					
					int questionsProblemSetsRowTwo = sheetArray.length + 2;// 总行
					
					for (; b < questionsProblemSetsRowTwo; b++) {
						
						ExportClassQuestionnaireSheet exportClassQuestionnaireSheet = new ExportClassQuestionnaireSheet();
						exportClassQuestionnaireSheet = (ExportClassQuestionnaireSheet) sheetArray[i];
						questionnaireValidCommond = ((ExportQuestionnaireBean) exportClassQuestionnaireSheet.getExportObject()).getExportClassQuestionnaireBeanList().get(0);
						pageInfo = questionnaireValidCommond.getStudentPageInfo().getPageInfo();
						selectProblemInfoGroup = pageInfo.getSelectProblemInfoGroup();
						multipleSelectProblemInfo = pageInfo.getMultipleSelectProblemInfo();
						essayQuestionInfo = pageInfo.getEssayQuestionInfo();
						int questionsProblemSetsCosOne = 1;// 起始列
						
						for (int k = 0; k < selectProblemInfoGroup.size(); k++) {// 遍历单选题组
							selectProblemIn = selectProblemInfoGroup.get(k);
							for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题
								selectProblemInfo = selectProblemIn.get(j);
								cell2 = row2.createCell(questionsProblemSetsCosOne);
								cell2.setCellValue("");
								for (ScoreStatisticsBean bean : scoreList) {
									if (bean.getQuestionId().equals(selectProblemInfo.getItemId())) {
										cell2.setCellValue(bean.getUnitermSum());
										break;
									}
								}
								cell2.setCellStyle(style5);
								questionsProblemSetsCosOne++;
							}
						}
						
						for (int k = 0; k < multipleSelectProblemInfo.size(); k++) {// 遍历多选题
							selectProblemInfo = multipleSelectProblemInfo.get(k);
							for (int j = 0; j < selectProblemInfo.getItemOption().size(); j++) {
								IOption = selectProblemInfo.getItemOption().get(j);
								cell2 = row2.createCell(questionsProblemSetsCosOne);
								for (MCQStatisticsBean bean : MCQList) {
									if (bean.getOptionNum().toString().equals(IOption.getOptionNum().toString()) && bean.getQuestionId().equals(selectProblemInfo.getItemId())) {
										cell2.setCellValue(bean.getSelectedNum());
										cell2.setCellStyle(style5);
									}
								}
								questionsProblemSetsCosOne++;
							}
						}
					}
				}
				break;
			case 1:
				cell2 = row2.createCell(0);
				cell2.setCellValue("单项平均分");
				cell2.setCellStyle(style5);
				for (int i = 0; i < sheetArray.length; i++) {
					
					int questionsProblemSetsRowTwo = sheetArray.length + 2;// 总行
					
					for (; b < questionsProblemSetsRowTwo; b++) {
						
						ExportClassQuestionnaireSheet exportClassQuestionnaireSheet = new ExportClassQuestionnaireSheet();
						exportClassQuestionnaireSheet = (ExportClassQuestionnaireSheet) sheetArray[i];
						questionnaireValidCommond = ((ExportQuestionnaireBean) exportClassQuestionnaireSheet.getExportObject()).getExportClassQuestionnaireBeanList().get(0);
						pageInfo = questionnaireValidCommond.getStudentPageInfo().getPageInfo();
						selectProblemInfoGroup = pageInfo.getSelectProblemInfoGroup();
						multipleSelectProblemInfo = pageInfo.getMultipleSelectProblemInfo();
						essayQuestionInfo = pageInfo.getEssayQuestionInfo();
						int questionsProblemSetsCosOne = 1;// 起始列
						
						for (int k = 0; k < selectProblemInfoGroup.size(); k++) {// 遍历单选题组
							selectProblemIn = selectProblemInfoGroup.get(k);
							for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题
								selectProblemInfo = selectProblemIn.get(j);
								cell2 = row2.createCell(questionsProblemSetsCosOne);
								cell2.setCellValue("");
								for (ScoreStatisticsBean bean : scoreList) {
									if (bean.getQuestionId().equals(selectProblemInfo.getItemId())) {
										cell2.setCellValue(bean.getUnitermAvg());
										break;
									}
								}
								cell2.setCellStyle(style5);
								questionsProblemSetsCosOne++;
							}
						}
					}
				}
				break;
			case 2:
				cell2 = row2.createCell(0);
				cell2.setCellValue("类总分");
				cell2.setCellStyle(style5);
				int questionsProblemSetsCosOne = 1;// 起始列
				int questionsProblemSetsCosTwo = 0;// 终止列
				for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
					selectProblemIn = selectProblemInfoGroup.get(k);
					questionsProblemSetsCosTwo += selectProblemIn.size();
					for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题标题
						selectProblemInfo = selectProblemIn.get(j);
						sheet.addMergedRegion(new CellRangeAddress(q, q, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
						cell2 = row2.createCell(questionsProblemSetsCosOne);
						for (ScoreStatisticsBean bean : scoreList) {
							if (bean.getQuestionId().equals(selectProblemInfo.getItemId())) {
								cell2.setCellValue(bean.getTestletSum());
								break;
							}
						}
						cell2.setCellStyle(style5);
						questionsProblemSetsCosOne++;
					}
				}
				break;
			case 3:
				cell2 = row2.createCell(0);
				cell2.setCellValue("类单项平均分");
				cell2.setCellStyle(style5);
				questionsProblemSetsCosOne = 1;// 起始列
				questionsProblemSetsCosTwo = 0;// 终止列
				for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
					selectProblemIn = selectProblemInfoGroup.get(k);
					questionsProblemSetsCosTwo += selectProblemIn.size();
					for (int j = 0; j < selectProblemIn.size(); j++) {// 遍历单选题标题
						selectProblemInfo = selectProblemIn.get(j);
						sheet.addMergedRegion(new CellRangeAddress(q, q, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
						cell2 = row2.createCell(questionsProblemSetsCosOne);
						for (ScoreStatisticsBean bean : scoreList) {
							if (bean.getQuestionId().equals(selectProblemInfo.getItemId())) {
								cell2.setCellValue(bean.getTestletAvg());
								break;
							}
						}
						cell2.setCellStyle(style5);
						questionsProblemSetsCosOne++;
					}
				}
				break;
			case 4:
				cell2 = row2.createCell(0);
				cell2.setCellValue("总项总分");
				cell2.setCellStyle(style5);
				questionsProblemSetsCosOne = 1;// 起始列
				questionsProblemSetsCosTwo = 0;// 终止列
				for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
					questionsProblemSetsCosTwo += selectProblemInfoGroup.get(k).size();
				}
				for (int v = 1; v <= questionsProblemSetsCosTwo; v++) {
					cell2 = row2.createCell(v);
					cell2.setCellStyle(style5);
				}
				if(questionsProblemSetsCosTwo!=0){
					sheet.addMergedRegion(new CellRangeAddress(q, q, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
					cell2 = row2.createCell(1);
					if (PropertyUtil.objectNotEmpty(scoreList) && PropertyUtil.objectNotEmpty(scoreList.get(0).getTotalSum())) {
						cell2.setCellValue(scoreList.get(0).getTotalSum());
					}
					cell2.setCellStyle(style5);
				}
				break;
			case 5:
				cell2 = row2.createCell(0);
				cell2.setCellValue("总项平均分");
				cell2.setCellStyle(style5);
				questionsProblemSetsCosOne = 1;// 起始列
				questionsProblemSetsCosTwo = 0;// 终止列
				for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
					questionsProblemSetsCosTwo += selectProblemInfoGroup.get(k).size();
				}
				for (int v = 1; v <= questionsProblemSetsCosTwo; v++) {
					cell2 = row2.createCell(v);
					cell2.setCellStyle(style5);
				}
				if(questionsProblemSetsCosTwo!=0){
					sheet.addMergedRegion(new CellRangeAddress(q, q, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
					cell2 = row2.createCell(1);
					if (PropertyUtil.objectNotEmpty(scoreList) && PropertyUtil.objectNotEmpty(scoreList.get(0).getTotalAvg())) {
						cell2.setCellValue(scoreList.get(0).getTotalAvg());
					}
					cell2.setCellStyle(style5);
				}
				break;
			case 6:
				cell2 = row2.createCell(0);
				cell2.setCellValue("总体平均分");
				cell2.setCellStyle(style5);
				questionsProblemSetsCosOne = 1;// 起始列
				questionsProblemSetsCosTwo = 0;// 终止列
				for (int k = 0; k < selectProblemInfoGroup.size(); k++) {
					questionsProblemSetsCosTwo += selectProblemInfoGroup.get(k).size();
				}
				for (int v = 1; v <= questionsProblemSetsCosTwo; v++) {
					cell2 = row2.createCell(v);
					cell2.setCellStyle(style5);
				}
				if(questionsProblemSetsCosTwo!=0){
					sheet.addMergedRegion(new CellRangeAddress(q, q, questionsProblemSetsCosOne, questionsProblemSetsCosTwo));
					cell2 = row2.createCell(1);
					if (PropertyUtil.objectNotEmpty(scoreList) && PropertyUtil.objectNotEmpty(scoreList.get(0).getAllAvg())) {
						cell2.setCellValue(scoreList.get(0).getAllAvg());
					}
					cell2.setCellStyle(style5);
				}
				break;
			}
		}
		
		return wb;
	}
	
	/**
	 * 获得二维码值
	 * @author RongSL
	 * @Date 2017-02-14
	 * */
	@RequestMapping("/getEWM")
	public void getEwm(HttpServletRequest request,HttpServletResponse respose){
		try {
			PrintWriter pw=respose.getWriter();
			pw.append(request.getSession().getAttribute("rand").toString());
			pw.flush();
			pw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}